package com.reader.cms.service.impl.common;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.reader.cms.entity.common.ReaderComment;
import com.reader.cms.entity.common.ReaderCommentReply;
import com.reader.cms.mapper.common.ReaderCommentMapper;
import com.reader.cms.mapper.common.ReaderCommentReplyMapper;
import com.reader.cms.service.common.IReaderCommentService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
/**
 * @@description  服务实现类
 * @author        gumenghao
 * @date          2018-10-31
 */
@Service
@Transactional
public class ReaderCommentServiceImpl extends ServiceImpl<ReaderCommentMapper, ReaderComment> implements IReaderCommentService {


@Autowired
private ReaderCommentMapper readerCommentMapper;

@Autowired
private ReaderCommentReplyMapper readerCommentReplyMapper;


/**
 * @function 多表关联查询
 * @param     currentPage 当前页
 * @param     size 每页显示条数
 * @param     docId 文章或音频ＩＤ
 * @return
 */
    @Transactional(readOnly=true)
    @Override
    public Page<ReaderComment> selectListPage(int currentPage,int size,String docId) {
            Page<ReaderComment> page = new Page<>(currentPage, size);// 当前页，总条数 构造 page 对象
            return page.setRecords(readerCommentMapper.selectListPage(page,docId));
    }

    /**
     * 回复评论
     * @param readerCommentReply
     * @return
     */
    @Override
    public boolean reply(ReaderCommentReply readerCommentReply) {
        boolean booleanResult = false;
        Integer update_num = 0;
        if(readerCommentReply.getId() == null){
            update_num = readerCommentReplyMapper.insert(readerCommentReply);
        }else {
            update_num = readerCommentReplyMapper.updateById(readerCommentReply);
        }
        if(update_num == 1){
            booleanResult = true;
        }
        return booleanResult;
    }

}